'use strict';
/**
 * 角色权限管理Service
 */
app.service('DeviceService',
['$http', '$q', 'dialogs', 
function ($http, $q, dialogs) {
	var that = this;
	this.getGridOptions = function(){
		var _gridWidth = 1024;
		var _columnWidth = _gridWidth / 7;
		return {
			//height: getGridHeight(),
			url: ISS.getPath('tpl/blocks/setting/device/data.json'),
			dataType: 'json',
			colModel : [
				{display : 'ID',name : 'deviceId',width : 150,hide : 'true'},
				    {display : 'device.snCode',name : 'devicesnCode',width : _columnWidth},
                    {display : 'device.name',name : 'devicename',width : _columnWidth},
                    {display : 'device.deviceType',name : 'deviceType',width : _columnWidth},
                    {display : 'device.installTime',name : 'deviceinstallTime',width : _columnWidth},
                    {display : 'device.deviceLocation',name : 'deviceLocation',width : _columnWidth},
                    {display : 'device.deviceStatus',name : 'deviceStatus',width : _columnWidth * 0.6},
				{display:'common.operation',name:"id", width : 150, process:function(value,index){
					var html = [];
					html.push('<button iss-permission="B_USER_UPDATE" class="btn m-r-xs btn-xs btn-primary" id="updateBtn" ng-click="vm.update('+ value +')">');
					html.push('<i class="fa fa-pencil"></i>');
					html.push('<span translate="common.edit"></span>');
					html.push('</button>');
					html.push('<button iss-permission="B_USER_DELETE" class="btn m-r-xs btn-xs btn-danger" id="delBtn" ng-click="vm.del('+ index +')">');
					html.push('<i class="fa fa-trash-o"></i>');
					html.push('<span translate="common.del"></span>');
					html.push('</button>');							
				 	return html.join('');
				}}
		        ],
				usepager: true,
		        showcheckbox: true,
		        rp: 10,
				isDragCol: true
			};
		}
		this.add = function(data){
			return $http.post(
					ISS.getPath('/user/add'),
					data,
					{contentType:'json'}
				).then(function(resp){
					return resp.data;
				});
		}
		this.update = function(data){
			delete data.createTime;
			return $http.post(
					ISS.getPath('/user/update'),
					data,
					{contentType:'json'}
				).then(function(resp){
					return resp.data;
				});
		}
		this.remove = function(data){
			return $http.post(
					ISS.getPath('/user/delete/'+ data.id + '/' + data.account)
					).then(function(resp){
						return resp.data;
					});
		}		
	}]);